Skip to content

Conversation

@Doc94
Copy link
Member

@Doc94 Doc94 commented Sep 17, 2025

Currently the API and events related to teleport allow put values out of bounds causing the player softlock or crash the servers (based in that coord is affected x/z or y) This PR make a check where teleport happens for throw an error before the change happen.
Closes #13023
Closes #13186

@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue Sep 17, 2025
@Doc94 Doc94 mentioned this pull request Oct 14, 2025
@Doc94 Doc94 force-pushed the feature/location-teleport-checks-bounds branch 2 times, most recently from 0556dbc to e07c1a2 Compare October 25, 2025 12:53
@Doc94
Copy link
Member Author

Doc94 commented Oct 25, 2025

Current tests...

@EventHandler
public void onPlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent event) {
   event.setTo(event.getTo().clone().add(0, 29999999, 0));
}

this allow me test a thing like teleport ~ ~ ~ and throw an error rather than softlock, and call any teleport method in API throw a issue too for the validations.

@Doc94 Doc94 marked this pull request as ready for review October 25, 2025 12:57
@Doc94 Doc94 requested a review from a team as a code owner October 25, 2025 12:57
Comment on lines 1950 to 1971
Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getFrom())), "origin for PlayerTeleportEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
if (!event.isCancelled()) {
Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getTo())), "destination for PlayerTeleportEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
}

return event;
}

public static PlayerTeleportEndGatewayEvent callPlayerTeleportEndGatewayEvent(ServerPlayer nmsPlayer, Location to, TheEndGatewayBlockEntity nmsTheEndGatewayBlockEntity) {
CraftPlayer entity = nmsPlayer.getBukkitEntity();
PlayerTeleportEndGatewayEvent event = new PlayerTeleportEndGatewayEvent(entity, entity.getLocation(), to, new org.bukkit.craftbukkit.block.CraftEndGateway(nmsPlayer.level().getWorld(), nmsTheEndGatewayBlockEntity));

event.callEvent();

Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getFrom())), "origin for PlayerTeleportEndGatewayEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
if (!event.isCancelled()) {
Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getTo())), "destination for PlayerTeleportEndGatewayEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y);
}

return event;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make a helper method to instead have to repeat all of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make a helper method to instead have to repeat all of this?

for take the event and check? if that then need remove that part where say what event is the issue in the Preconditions not?

Copy link
Contributor

@Lulu13022002 Lulu13022002 Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks should be in the event, otherwise the stacktrace is useless for plugins.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that values are not in the event (api) for make the checks in that...

Not sure how can manage this... If add a magic value in Locations and check or another better way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the better way would be to move the event impl into the server like PaperInventoryMoveItemEvent for example or just a bridge.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, lets make the event have a server implementation and check the bounds there. Checking the bounds after is an issue because exceptions thrown there aren't caught like ones thrown inside event handlers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then need make a impl for like 4 classes not?
a PaperPlayerTeleportEndGatewayEvent and PaperPlayerTeleportEvent (with the Entity side event) with a override in the set for add the check not?

@Doc94 Doc94 force-pushed the feature/location-teleport-checks-bounds branch from e07c1a2 to a54436a Compare November 1, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

Teleporting player outside level coordinates crashes the server Teleporting a player above y 20000500 softlocks the player

4 participants